import {Component, OnInit, OnDestroy} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";

@Component({
    selector: 'bootstrap',
    templateUrl: 'bootstrap.component.html',
    styleUrls: ['bootstrap.component.scss'],
})
export class BootstrapComponent implements OnInit, OnDestroy {
    index;
    type;
    id;
    constructor(public router: Router, public route: ActivatedRoute) {
        console.log(this.route, 11, 'bootstrapComponent');
        route.params.subscribe(params=>{
            this.index = +params['index'];
            console.log(params,16,'BootstrapComponent');
        });

        route.firstChild && route.firstChild.params
            .subscribe(params=>{
                this.type = +params['type'];
            });

        route.firstChild &&route.firstChild.firstChild && route.firstChild.firstChild.params
            .subscribe(params=>{
                this.id = +params['id'];
            })
    }

    ngOnInit() {
        console.log(this.route, 11, 'bootstrapComponent-init');
    }

    changeItem(item) {
        if(item > 4){
            this.router.navigate([item,this.type,this.id]);
        }else{
            this.router.navigate([item,this.id],{relativeTo:this.route});
        }
    }

    ngOnDestroy() {

    }
}
